﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using EFEntity;
using Iservices;
using Microsoft.EntityFrameworkCore;
using Model;

namespace Services
{
    public class config_file_third_kindServices : Iconfig_file_third_kindServices
    {
        private readonly MyDbContext myDbContext;
        private readonly IMapper mapper;
        public config_file_third_kindServices(MyDbContext myDbContext, IMapper mapper)
        {
            this.myDbContext = myDbContext;
            this.mapper = mapper;
        }

        public async Task<int> TestAdd(config_file_third_kind config_File)
        {
            Econfig_file_third_kind ec = mapper.Map<Econfig_file_third_kind>(config_File);
            myDbContext.econfig_File_Third_Kinds.Add(ec);
            int reslut = await myDbContext.SaveChangesAsync();
            return reslut;
        }

        public async Task<int> TestDel(int Id)
        {
            Econfig_file_third_kind ec = new Econfig_file_third_kind();
            ec = myDbContext.econfig_File_Third_Kinds.Find(Id);
            myDbContext.econfig_File_Third_Kinds.Remove(ec);
            return await myDbContext.SaveChangesAsync(); ;
        }

        public async Task<List<config_file_third_kind>> TestSelect()
        {
            List<Econfig_file_third_kind> list = new List<Econfig_file_third_kind>();
            await Task.Run(() =>
            {
                list = myDbContext.econfig_File_Third_Kinds.ToList();
            });
            List<config_file_third_kind> list2 = mapper.Map<List<config_file_third_kind>>(list);
            return list2;
        }

        public async Task<int> TestUpdate(config_file_third_kind config_File)
        {

            Econfig_file_third_kind ec = mapper.Map<Econfig_file_third_kind>(config_File);
            myDbContext.Attach(ec);
            myDbContext.Entry<Econfig_file_third_kind>(ec).State = EntityState.Modified;
            return await myDbContext.SaveChangesAsync();
        }
    }
}
